package com.hujf.mapreduce.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author Hujf
 * @title: WordCountMapper
 * @date 2021/3/3011:51
 * @description: mapper子类
 * KEYIN,   map阶段输入的key类型   longWritable类型 偏移量
 * VALUEIN,  当前行内容    text类型
 * KEYOUT,   输出   单词 text
 * VALUEOUT   次数  int
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private Text text = new Text();
    private IntWritable outV=new IntWritable(1);
    /**
     *每行都进入  context 联络员
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.获取一行的数据
        String[] split = value.toString().split(" ");

        //循环写出
        for (String s : split) {
            text.set(s);
            context.write(text,outV);
        }
    }
}
